<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>欢迎页面-X-admin2.2</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="./css/font.css">
        <link rel="stylesheet" href="./css/xadmin.css">
		<link rel="stylesheet" href="js/Cesium/Widgets/widgets.css" />
        <script src="./lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="./js/xadmin.js"></script>
		<script src="js/Cesium/Cesium.js"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
		<style>
			html,body{
				margin: 0;
				padding: 0;
				height: 100%;
				width: 100%;
			}
			#contanter{
				width:100%;
				height:100%
			}    
			/* 去除logo信息 */	
			.cesium-widget-credits{ 
				display:none!important; 
				visibility:hide!important; 
			} 
			/* 添加点、线、面的按钮*/
			.addEntities{
				position: fixed;
				left: 110px;
				top: 10px;
				z-index: 99999;
			}
			button{
				background-color: rgba(47,53,60,0.8);
				color: #FFFFFF;
				border: 0;
				padding: 5px 15px;
				border-radius: 5px;
			}
		</style>
    </head>
    <body>
		<div id="contanter"></div>
		<div class="addEntities">
			<button onclick="showSnow()">降雪</button>
			<button onclick="removeStage()">停止降雪</button>
		</div>
		<script>
			var viewer = new Cesium.Viewer("contanter",{
				animation: false,  //是否显示动画控件
	            baseLayerPicker: false, //是否显示图层选择控件
	            geocoder: true, //是否显示地名查找控件
	            timeline: false, //是否显示时间线控件
	            sceneModePicker: true, //是否显示投影方式控件
	            navigationHelpButton: false, //是否显示帮助信息控件
	            infoBox: true,  //是否显示点击要素之后显示的信息
			})
			
			const tileset = new Cesium.Cesium3DTileset({ url: './data/SampleData/3dtiles1/tileset.json' });
			
			tileset.readyPromise.then(function(tileset) {
			     viewer.scene.primitives.add(tileset);
			     viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0.5, -0.2, tileset.boundingSphere.radius * 1.0));
			}).otherwise(function(error) {
			     console.log(error);
			});
			
			  //定义下雪场景 着色器
			function getSonwShader() {
				return `uniform sampler2D colorTexture;\n\
					varying vec2 v_textureCoordinates;\n\
					\n\
					float snow(vec2 uv,float scale)\n\
					{\n\
						float time = czm_frameNumber / 60.0;\n\
						float w=smoothstep(1.,0.,-uv.y*(scale/10.));if(w<.1)return 0.;\n\
						uv+=time/scale;uv.y+=time*2./scale;uv.x+=sin(uv.y+time*.5)/scale;\n\
						uv*=scale;vec2 s=floor(uv),f=fract(uv),p;float k=3.,d;\n\
						p=.5+.35*sin(11.*fract(sin((s+p+scale)*mat2(7,3,6,5))*5.))-f;d=length(p);k=min(d,k);\n\
						k=smoothstep(0.,k,sin(f.x+f.y)*0.01);\n\
						return k*w;\n\
					}\n\
					\n\
					void main(void){\n\
						vec2 resolution = czm_viewport.zw;\n\
						vec2 uv=(gl_FragCoord.xy*2.-resolution.xy)/min(resolution.x,resolution.y);\n\
						vec3 finalColor=vec3(0);\n\
						float c = 0.0;\n\
						c+=snow(uv,30.)*.0;\n\
						c+=snow(uv,20.)*.0;\n\
						c+=snow(uv,15.)*.0;\n\
						c+=snow(uv,10.);\n\
						c+=snow(uv,8.);\n\
					c+=snow(uv,6.);\n\
						c+=snow(uv,5.);\n\
						finalColor=(vec3(c)); \n\
						gl_FragColor = mix(texture2D(colorTexture, v_textureCoordinates), vec4(finalColor,1), 0.5); \n\
					\n\
					}\n\
				`;
			}
			// 改变天空的颜色
			function changeSkyStyle(){
				viewer.scene.skyAtmosphere.hueShift = -0.8;
				viewer.scene.skyAtmosphere.saturationShift = -0.7;
				viewer.scene.skyAtmosphere.brightnessShift = -0.33;
				viewer.scene.fog.density = 0.001;
				viewer.scene.fog.minimumBrightness = 0.8;
			}
			// 显示降雨
			var lastStage = null
			function showSnow() {
				removeStage();
				var e = new Cesium.PostProcessStage({
						name: "czm_rain",
						fragmentShader: getSonwShader()
				});
				viewer.scene.postProcessStages.add(e); 
				lastStage = e
				changeSkyStyle()
			}
			
			// 移除降雨
			function removeStage() {
				if(lastStage){
					viewer.scene.postProcessStages.remove(lastStage);
					lastStage = null
				}
			}
		

	
		
		</script>
    </body>
</html>